(function() {
  var $school_languages, add_language, confirm_add_language, hide_add_language, refresh_language;

  window.language = {};

  $school_languages = {};

  add_language = function() {
    return $('#add-language').modal();
  };

  confirm_add_language = function() {
    var la, language, tbody;
    console.log("Confirming add language");
    la = $('#language-select').val();
    $school_languages[la] = [];
    language = $school_languages[la];
    tbody = "";
    if ($('#101-checkbox').attr('checked')) {
      $school_languages[la].push('101');
      tbody += "<tr><td>101</td></tr>";
    }
    if ($('#201-checkbox').attr('checked')) {
      $school_languages[la].push('201');
      tbody += "<tr><td>201</td></tr>";
    }
    if ($('#301-checkbox').attr('checked')) {
      $school_languages[la].push('301');
      tbody += "<tr><td>301</td></tr>";
    }
    refresh_language(la, tbody);
    return hide_add_language();
  };

  refresh_language = function(la, tbody) {
    if ($("" + la + "-display").length > 0) $("" + la + "-display").remove();
    return $('#class-display').prepend("<table id=\"" + la + "-display\" class=\"table-bordered span2 textcenter\" style=\"height:300px\">\n  <thead><tr><th>" + la + "</th></tr></thead>\n  <tbody>\n    " + tbody + "\n    <tr><td><a class=\"btn btn-dark btn-small\" onclick=\"language.remove('" + la + "')\">Remove</a></td></tr>\n  </tbody>\n</table>");
  };

  hide_add_language = function() {
    console.log("Hiding add language");
    return $('#add-language').modal('hide');
  };

  language.remove = function(la) {
    return $("" + la + "-display").remove();
  };

  language.initialize = function() {
    $('#add-language-btn').click(add_language);
    console.log("Initializing ...");
    console.log($('#confirm-language-btn'));
    $('#confirm-language-btn').click(confirm_add_language);
    return $('#cancel-language-btn').click(hide_add_language);
  };

}).call(this);

(function() {

  window.initialize = function(data) {
    common.initialize();
    language.initialize();
    return $('#school-name').text(data.sn);
  };

}).call(this);
